package com.hexinfo.dmpro.dev.data.transfer.model.dto;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.hutool.core.util.StrUtil;
import com.hexinfo.dmpro.dev.data.transfer.model.DesensitizeFieldList;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

@Data
public class FieldListDto extends ExcelVerifyInfo{
    @Excel(name = "库名")
    @NotBlank(message = "        [库名]不能为空")
    @Pattern(regexp = "^[0-9A-Za-z_]+$", message = "        [库名]只能输入大小写英文字母和下划线")
    @Size(max = 100, message = "        [任务编码]长度不能大于100位")
    private String dbName;

    @Excel(name = "表名")
    @NotBlank(message = "        [表名]不能为空")
    @Pattern(regexp = "^[0-9A-Za-z_]+$", message = "        [表名]只能输入大小写英文字母和下划线")
    @Size(max = 100, message = "        [任务名称]长度不能大于100位")
    private String tableName;

    @Excel(name = "字段名称")
    @NotBlank(message = "        [字段名称]不能为空")
    @Pattern(regexp = "^[0-9A-Za-z_]+$", message = "        [字段名称]只能输入大小写英文字母和下划线")
    @Size(max = 100, message = "        [字段名称]长度不能大于100位")
    private String fieldName;

    @Excel(name = "脱敏函数")
    @NotBlank(message = "        [脱敏函数]不能为空")
    @Size(max = 100, message = "        [脱敏函数]长度不能大于100位")
    private String desensitizeFunction;

    public String getFullField(){
        return StrUtil.format("{}.{}.{}",dbName,tableName,fieldName);
    }

    public DesensitizeFieldList toDesensitizeFieldList(){
        DesensitizeFieldList fieldList = new DesensitizeFieldList();
        fieldList.setFieldName(fieldName);
        fieldList.setDbName(dbName);
        fieldList.setTableName(tableName);
        fieldList.setDesensitizeFunction(desensitizeFunction);
        return fieldList;
    }

    public boolean isEmpty(){
        return StrUtil.isEmpty(dbName)&&StrUtil.isEmpty(tableName)&&StrUtil.isEmpty(fieldName)&&StrUtil.isEmpty(desensitizeFunction);
    }
}
